Move the should_use_portal helper to gdk
authorMatthias Clasen <mclasen@redhat.com>
Thu, 1 Nov 2018 17:46:04 +0000 (13:46 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 4 Nov 2018 13:17:32 +0000 (08:17 -0500)
We want to use it there too, in the future.
Update all callers.

gdk/gdk-private.h
gdk/gdk.c
gtk/gtkapplication-dbus.c
gtk/gtkcolorpickerportal.c
gtk/gtkfilechoosernativeportal.c
gtk/gtkprintoperation-unix.c
gtk/gtkprivate.c
gtk/gtkprivate.h

index f6c712c3e77295dfaa2d01c2b444d0f269f9f032..0c83002bfc4a35dbbdb7975e7a34183e56de1ddb 100644 (file)
@@ -32,6 +32,7 @@ void gdk_display_set_cursor_theme          (GdkDisplay   *display,
                                             const char   *theme,
                                             int           size);
 gboolean gdk_running_in_sandbox (void);
+gboolean gdk_should_use_portal (void);
 
 const gchar *   gdk_get_startup_notification_id (void);
 
index c67706779db060a6d265bc06c2ce002c9a9156b8..d623afabf9eaab10251275c3061c3eef68188e3d 100644 (file)
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -272,6 +272,26 @@ gdk_running_in_sandbox (void)
   return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
 }
 
+gboolean
+gdk_should_use_portal (void)
+{
+  static const char *use_portal = NULL;
+
+  if (G_UNLIKELY (use_portal == NULL))
+    {
+      if (gdk_running_in_sandbox ())
+        use_portal = "1";
+      else
+        {
+          use_portal = g_getenv ("GTK_USE_PORTAL");
+          if (!use_portal)
+            use_portal = "";
+        }
+    }
+
+  return use_portal[0] == '1';
+}
+
 /**
  * SECTION:threads
  * @Short_description: Functions for using GDK in multi-threaded programs
index f089e064836c7443f8ad9237286bed95468117a3..e83265091cbf5402b0d385491bb6a931cc203a61 100644 (file)
@@ -259,7 +259,7 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
   dbus->object_path = g_application_get_dbus_object_path (G_APPLICATION (impl->application));
   dbus->unique_name = g_dbus_connection_get_unique_name (dbus->session);
 
-  if (gtk_should_use_portal ())
+  if (gdk_should_use_portal ())
     goto out;
 
   g_debug ("Connecting to session manager");
index 3198545a0b606acd7f3c162fdeeb9a38c72264f3..993427bb6e9e673c3dcd888054008fea0a4d2547 100644 (file)
@@ -53,7 +53,7 @@ gtk_color_picker_portal_initable_init (GInitable     *initable,
   GVariant *ret;
   guint version;
 
-  if (!gtk_should_use_portal ())
+  if (!gdk_should_use_portal ())
     return FALSE;
 
   picker->portal_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
index 4073bb08147940420d45e9d3d90951e8fe99585b..912013140eccc10cb9e2bd54c25bee77885b2fd7 100644 (file)
@@ -406,7 +406,7 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
   GtkFileChooserAction action;
   const char *method_name;
 
-  if (!gtk_should_use_portal ())
+  if (!gdk_should_use_portal ())
     return FALSE;
 
   connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
index 7c044120b9e83c49ddcc868c502d0888fa9e29d4..85cc1718059cf5aff867c78aa23060dd2fe0541d 100644 (file)
@@ -1217,7 +1217,7 @@ _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
                                                  GtkWindow         *parent,
                                                  gboolean          *do_print)
 {
-  if (gtk_should_use_portal ())
+  if (gdk_should_use_portal ())
     return gtk_print_operation_portal_run_dialog (op, show_dialog, parent, do_print);
   else
     return gtk_print_operation_unix_run_dialog (op, show_dialog, parent, do_print);
@@ -1228,7 +1228,7 @@ _gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation
                                                         GtkWindow                  *parent,
                                                        GtkPrintOperationPrintFunc  print_cb)
 {
-  if (gtk_should_use_portal ())
+  if (gdk_should_use_portal ())
     gtk_print_operation_portal_run_dialog_async (op, show_dialog, parent, print_cb);
   else
     gtk_print_operation_unix_run_dialog_async (op, show_dialog, parent, print_cb);
@@ -1240,7 +1240,7 @@ _gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
                                                       GtkWindow         *parent,
                                                       const gchar       *filename)
 {
-  if (gtk_should_use_portal ())
+  if (gdk_should_use_portal ())
     gtk_print_operation_portal_launch_preview (op, surface, parent, filename);
   else
     gtk_print_operation_unix_launch_preview (op, surface, parent, filename);
index 0d3dfd78a08c5df39b94c3a6122b112a57df1bde..8de1e81a5e8b23ff95642570811e32e21544603e 100644 (file)
@@ -268,30 +268,6 @@ _gtk_ensure_resources (void)
   g_once (&register_resources_once, register_resources, NULL);
 }
 
-gboolean
-gtk_should_use_portal (void)
-{
-  static const char *use_portal = NULL;
-
-  if (G_UNLIKELY (use_portal == NULL))
-    {
-      char *path;
-
-      path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);
-      if (g_file_test (path, G_FILE_TEST_EXISTS))
-        use_portal = "1";
-      else
-        {
-          use_portal = g_getenv ("GTK_USE_PORTAL");
-          if (!use_portal)
-            use_portal = "";
-        }
-      g_free (path);
-    }
-
-  return use_portal[0] == '1';
-}
-
 static char *
 get_portal_path (GDBusConnection  *connection,
                  const char       *kind,
index 58b245393069c9e9ecc3fe0ea288daee95922e33..3662d688382947b7687e5146875173b5dac73909 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <glib-object.h>
 #include <gdk/gdk.h>
+#include <gdk/gdk-private.h>
 
 #include "gtkcsstypesprivate.h"
 #include "gtktexthandleprivate.h"
@@ -109,7 +110,6 @@ GtkWidget *     _gtk_toplevel_pick (GtkWindow *toplevel,
 gdouble _gtk_get_slowdown (void);
 void    _gtk_set_slowdown (gdouble slowdown_factor);
 
-gboolean gtk_should_use_portal (void);
 char *gtk_get_portal_request_path (GDBusConnection  *connection,
                                    char            **token);
 char *gtk_get_portal_session_path (GDBusConnection  *connection,